/**
 *
 * @author Reebdoog
 *
 * MonoPort (v.0.3)
 * A Plugin by Reebdoog
 * Compatible with hey0 mod build 117
 * Source code borrowed from the Balls plugin and Grief Alert
 * ArrayList idea from Cuboid
 *
 * Minor modifications by Eric Hushagen
 */

//Need libraries
import java.util.logging.Logger;
import java.util.List;

public class MonoPort extends Plugin {{

}
    static final MonoPortListener listener = new MonoPortListener();
    protected static final Logger log = Logger.getLogger("Minecraft");

    public void enable() {
        addCustomCommands();
        log.info("MonoPortEHMod v.0.3 plugin enabled");
        tellMods("MonoPortEHMod v.0.3 plugin enabled");
        if (listener.properties == null) {
           listener.properties = new PropertiesFile("monoport.properties");
        } else {
            listener.properties.load();
        }
        listener.checkDataFile();
        if (!listener.loadPortalsIntoArray())
        {
            log.info("[ERROR] MonoPortEHMod plugin: Couldn't load all portals");
            tellMods("[ERROR] MonoPortEHMod plugin: Couldn't load all portals");
        }
    }

    public void disable() {
        removeCustomCommands();
        log.info("MonoPortEHMod v.0.3 plugin disabled");
        tellMods("MonoPortEHMod v.0.3 plugin disabled");
    }

    public void initialize() {
        //Add Hooks
        etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM);
        etc.getLoader().addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this, PluginListener.Priority.MEDIUM);
        etc.getLoader().addListener(PluginLoader.Hook.PLAYER_MOVE, listener, this, PluginListener.Priority.MEDIUM);
    }

    public void addCustomCommands(){
        etc.getInstance().addCommand("/setdest", "- Sets a portal Destination");
        etc.getInstance().addCommand("/showportallinks", "- Shows a list of Portal Links");
        etc.getInstance().addCommand("/showdestinations", "- Shows a list of Possible Destinations");
        etc.getInstance().addCommand("/makeportal", "- Makes a portal");
        //etc.getInstance().addCommand("/modifyportal", "- Modifies a portal");
        etc.getInstance().addCommand("/delportal", "- Deletes a portal");
    }

    public void removeCustomCommands(){
        etc.getInstance().removeCommand("/setdest");
        etc.getInstance().removeCommand("/showportallinkst");
        etc.getInstance().removeCommand("/showdestinations");
        etc.getInstance().removeCommand("/makeportal");
        //etc.getInstance().removeCommand("/modifyportal");
        etc.getInstance().removeCommand("/delportal");
    }

    public void tellMods(String message) {
        List<Player> pList = etc.getInstance().getServer().getPlayerList();
        for (Player p : pList) {
            if (p.isInGroup("mods")) {
                p.sendMessage(Colors.Rose + message);
            }
        }
    }
}
